<template>
  <div class="exam-page">
    <div class="exam-content">
      <div class="exam-title">汽车制造安全常识培训-第12次考试</div>
      <div
        class="exam-question-list"
        v-for="(question, index) in questionsList"
        :key="question.id"
      >
        <div class="question-content">
          <div class="question-required">*</div>
          <div class="question-index">{{ index + 1 }}. &nbsp;</div>
          <div class="question-title">
            {{ question.questionName }}
          </div>
          <el-tag size="mini" effect="plain">
            {{ getQuestionTypeLabel(question.questionType) }}
          </el-tag>
          <el-tag
            size="mini"
            effect="plain"
            type="info"
            style="margin-left: 5px"
          >
            {{ question.score }}&nbsp;分
          </el-tag>
          <!-- <div class="question-score">{{ question.score }}分</div> -->
        </div>
        <div class="question-options">
          <el-checkbox-group
            v-if="question.questionType === 'MultiChoice'"
            v-model="question.result"
            :key="question.id"
          >
            <el-checkbox
              class="question-options-item"
              v-for="option in question.optionList"
              :label="option.optionCode"
              :key="option.optionCode"
            >
              {{ option.optionName }}
            </el-checkbox>
          </el-checkbox-group>
          <el-radio
            class="question-options-item"
            v-else
            v-model="question.result"
            v-for="option in question.optionList"
            :label="option.optionCode"
            :key="option.optionCode"
          >
            {{ option.optionName }}
          </el-radio>
        </div>
      </div>
      <div class="exam-submit">
        <el-button type="primary" @click="submitExam">提交</el-button>
        <el-button @click="closeExam">关闭</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import { exam_questions_list_mock } from "./mock.js";

export default {
  name: "examDemo",
  data() {
    return {
      msg: "测试组件",
      dialogVisible: true,
      questionTypeOptions: [
        { value: "Judgment", label: "判断题" },
        { value: "SingleChoice", label: "单选题" },
        { value: "MultiChoice", label: "多选题" },
      ],
      questionsList: [],
    };
  },
  mounted() {
    console.log(exam_questions_list_mock);
    // 清空分类列表
    this.questionsList = [];
    console.log(this.questionsList);
    // 填充分类列表
    this.questionsList = exam_questions_list_mock.map((item) => ({
      ...item,
      result: item.questionType === "MultiChoice" ? [] : "",
    }));
    console.log(this.questionsList);
  },
  methods: {
    submitExam() {},
    closeExam() {},
    getQuestionTypeLabel(questionType) {
      const option = this.questionTypeOptions.find(
        (item) => item.value === questionType
      );
      return option ? option.label : "";
    },
  },
};
</script>
<style scoped>
.exam-page {
  width: 100%;
  height: 100%;
  background-image: url("@/assets/exam-bg.png");
  background-size: cover;
  overflow: auto;
}
.exam-content {
  width: 980px;

  padding: 30px 50px;
  margin: 20px calc(50% - 490px);
  margin-bottom: 100px;
  box-sizing: border-box;
  text-align: left;
  color: #303133;
  background: #fff;
}
.exam-title {
  text-align: center;
  margin-bottom: 30px;
  font-size: 24px;
  font-family: "heiti";
}
.question-content {
  font-size: 16px;
  margin-bottom: 15px;
  margin-right: 10px;
  line-height: 1.5rem;
  display: flex;
}
.question-required {
  color: red;
  font-weight: bold;
  margin-right: 3px;
}
.question-index {
  font-family: "heiti";
  font-weight: bold;
}
.question-title {
  margin-right: 10px;
}
.question-score {
  flex: 1;
  text-align: right;
}
.exam-list {
  flex: 3;
  display: flex;
  flex-direction: column;
}
.exam-divider {
  height: 100%;
}
.exam-content {
  flex: 7;
}
.exam-question-list {
  margin-bottom: 30px;
}
.question-options-item {
  margin-bottom: 10px;
  display: block;
}
.exam-submit {
  text-align: center;
}
</style>
